import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
public class Circuit
{
	private HashMap<String,GATE> gates_name;
	private ArrayList<GATE> gates_definition;
	private ArrayList<GateBlock> gate_blocks=new ArrayList<GateBlock>();
	private int step=0;
	private ArrayList<QVAR> variables;
	public Circuit()
	{
		gates_name=new HashMap<String,GATE>();
		gates_definition=new ArrayList<GATE>();
		variables=new ArrayList<QVAR>();
	}
	public void addGateDefinition(GATE g)
	{
		if(!gates_name.containsKey(g.getName()))
		 {
			gates_definition.add(g);
			gates_name.put(g.getName(),g);
		 }
	}
	public void addGateBlock(GateBlock gb)
	{
		gate_blocks.add(gb);
	}
	public void addVar(QVAR v)
	{
		variables.add(v);
	}
	public void output()
	{
		System.out.println("");
		int step=1;
		for(QVAR v:variables)
		{
			System.out.println("VAR "+v.getName());
		}
		System.out.println("");
		for(GATE gate:gates_definition)
		{
			gate.printDefinition();
			//gate.squareRoot();
		}
		System.out.println("");
		for(GateBlock gb:gate_blocks)
		{
			gb.output();
		}
	}
}
